<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
    public function login()
    {
        if (request()->isMethod('post')){
            if (!Auth::attempt(['username' => request('username'), 'password' => request('password')])) {
                return ['code' => 1, 'msg'=> '账号或密码有误'];
            }
            return ['code' => 0, 'data' => Auth::user(), 'msg'=> '登录成功'];
        }
        return view('home/login');
    }
}
